<?php
function sms_msg($options, $account, $password, $sign) {
    $target = 'http://api.chanzor.com/send';
    $to = urlencode($options['to']);
    $sign = $sign ? $sign : '【零公里房车】';
    $password = $password ? $password :strtoupper(md5('p6gz3h9co7'));
    $account = $account ? $account : '98a3a8';
    $content = $options['content'] . $sign;
    $data = "?account=$account&password=$password&mobile=$to&sendTime=&content=" . rawurlencode($content);
//    $url_info = parse_url($target);
//    $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
//    $httpheader .= "Host:" . $url_info['host'] . "\r\n";
//    $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
//    $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
//    $httpheader .= "Connection:close\r\n\r\n";
//    //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
//    $httpheader .= $data;
//    $fd = fsockopen($url_info['host'], 80);
//    fwrite($fd, $httpheader);
//    $gets = "";
//    while (!feof($fd)) {
//        $gets .= fread($fd, 128);
//    }
//    Log::record($gets, Log::DEBUG, true);
//    fclose($fd);
//    $start = strpos($gets, "<?xml");
//    $data = substr($gets, $start);
//    $xml = simplexml_load_string($data);
//    $json = (json_decode(json_encode($xml), TRUE));
    $result = file_get_contents($target.$data);
    Log::record($result, Log::DEBUG, true);
    $json = (json_decode($result, TRUE));
    if (!empty($json['taskId'])) {
        return true;
        Log::record('短信通道2 发送成功', Log::DEBUG, true);
    } else {
        Log::record('短信通道2 发送失败', Log::DEBUG, true);
        return false;
    }
}